package com.ludomancy.gamelib.verlet;

import java.util.ArrayList;

import com.ludomancy.gamelib.MathHelper;

public class Vertex
{
	public float px;
	public float py;
	public float old_px;
	public float old_py;
	public float forceX;
	public float forceY;
	public ArrayList edges = new ArrayList();
	public boolean fixed = false;
	public float radii;
	
	public Vertex(float x, float y, float radii)
	{
		this(x, y, 0, 0, radii);
	}
	
	public Vertex(float x, float y, float speedX, float speedY, float radii)
	{
		px = x;
		py = y;
		old_px = x - speedX;
		old_py = y - speedY;
		this.radii = radii;
	}
	
	public void limitVelocity(float velMagnitude)
	{
		float speed = MathHelper.dist(px, py, old_px, old_py);
		if(speed > velMagnitude)
		{
			float k = (1 - velMagnitude/speed);
			old_px += velX() * k;
			old_py += velY() * k;
		}
	}
	
	public void push(float x, float y)
	{
		px += x;
		py += y;
	}
		
	public void move(float x, float y)
	{
		px += x;
		py += y;
		old_px += x;
		old_py += y;
	}
	
	public float velX()
	{
		return px-old_px;
	}
	
	public float velY()
	{
		return py-old_py;
	}	

	public void stop()
	{
		old_px = px;
		old_py = py;
	}
}
